package com.dongge.common;

import java.io.*;

/**
 * Created by Administrator on 2015/10/2.
 */
public class FileUtils {
    public static void copyFile(File in,File out)throws IOException{
        if(!in.exists()){
            throw new FileNotFoundException("文件不存在");
        }
        if(!out.getParentFile().exists()){
            out.getParentFile().mkdirs();
        }
        copyFile(new FileInputStream(in),new FileOutputStream(out));
    }

    public static void copyFile(File in,String outPath) throws IOException{
        if(!in.exists()){
            throw new FileNotFoundException("文件不存在");
        }
        File out = new File(outPath);
        if(!out.getParentFile().exists()){
            out.getParentFile().mkdirs();
        }
        copyFile(in,out);
    }

    public static void copyFile (InputStream inputStream,OutputStream outputStream)throws IOException {
        byte[]buf = new byte[1024];
        while(inputStream.read(buf)!=-1){
            outputStream.write(buf);
        }
        outputStream.flush();
        outputStream.close();
        inputStream.close();
    }
}
